package com.learning.mybatis.base.simple.annotation.mapper;

import com.learning.mybatis.base.simple.annotation.entity.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * ClassName: IUserMapping
 * Description:
 * Date: 2020/7/22 9:56 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
public interface IUserMapper {
    /**
     * 新增
     *
     * @param user
     * @return
     */
    @Insert(value = "INSERT INTO learning_mybatis.t_user (id, name, age, create_time) VALUES (#{id}, #{name}, #{age}, #{createTime})")
    int add(User user);

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Delete(value = "DELETE FROM learning_mybatis.t_user WHERE id = #{id}")
    int delete(int id);

    /**
     * 更新
     *
     * @param user
     * @return
     */
    @Update(value = "UPDATE learning_mybatis.t_user SET name = #{name}, age  = #{age} WHERE id = #{id}")
    int update(User user);

    /**
     * 查询
     *
     * @param id
     * @return
     */
    @Select(value = "SELECT id, name, age, create_time AS createTime FROM learning_mybatis.t_user WHERE id = #{id}")
    User select(@Param("id") int id);


}
